package controller.sistema_veiculos;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.Usuario;

@WebServlet("/ServletAutenticacaoSistemaVeiculos")
public class ServletAutenticacaoSistemaVeiculos extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public ServletAutenticacaoSistemaVeiculos() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		RequestDispatcher dispatcher = null; 
		HttpSession session = request.getSession();
		String login = request.getParameter("usuario");
		String senha = request.getParameter("senha");
		
		if(login.equalsIgnoreCase(senha)){
			Usuario usuario = new Usuario(login, "", "", "");
			session.setAttribute("usuario", usuario);
			dispatcher = request.getRequestDispatcher("/sistema_veiculos/menu.jsp");
			dispatcher.forward(request, response);
		}else{
			dispatcher = request.getRequestDispatcher("/sistema_veiculos/index.jsp");
			dispatcher.forward(request, response);
		}
	}
}